import java.util.ArrayList;
import java.util.List;

public class Solution179 {
    public String largestNumber(int[] nums) {
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        list.sort((o1, o2) -> {
            char[] a = o1.toString().toCharArray();
            char[] b = o2.toString().toCharArray();
            int i = 0;
            while (i < a.length + b.length) {
                char ai = i < a.length ? a[i] : b[i - a.length];
                char bi = i < b.length ? b[i] : a[i - b.length];
                if (ai < bi) {
                    return 1;
                } else if (ai > bi) {
                    return -1;
                }
                i++;
            }
            return 0;
            /*if (o1 == 0 || o2 == 0) {
                return o2 - o1;
            }
            int i = 0, t = o1, a = o1, b = o2;
            while (t != 0) {
                b *= 10;
                t /= 10;
            }
            b += o1;
            t = o2;
            while (t != 0) {
                a *= 10;
                t /= 10;
            }
            a += o2;
            return b - a;*/
        });
        if (list.get(0) == 0) {
            return "0";
        }
        StringBuilder res = new StringBuilder();
        for (Integer integer : list) {
            res.append(integer);
        }
        return res.toString();
    }
}
